<?php
require_once(dirname(__FILE__)."/config.php");
require_once(QFINC."/common.func.php");

//Ȩ����֤
//if(strtolower($_SESSION["qf_admin_id"]) != "admin")
//$adminid = $cuserLogin->getUserID();
//if(strtolower($adminid) != "admin")
//{
//	ShowMsg('ֻ�й���Ա�������վ�㣡',"blank.htm");
//    exit();
//}

if(empty($dopost)) $dopost = '';
if(empty($sid)) $sid = '';
if(empty($pid)) $pid = '';
if(empty($cid)) $cid = '';

if($dopost != 'save')
{
	//...
	include(QFADMIN.'/templets/add_col.htm');
	
	exit();
}
else if($dopost=='save')
{
	//	if(empty($sitename))
	//	{
	//		ShowMsg("��վ��Ʋ���Ϊ��!", "-1");
	//		exit();
	//	}
	
	//$sql="insert into xxx_table (xxx_date , xxx_datetime) values( curdate(),now() )";
	//$ntime = time();
	//$ntime = date("Y-m-d H:i:s", strtotime("2001-1-1 20:11:11"));
	$ntime = date("Y-m-d H:i:s" ,time());	
	//$siteid = uniqid("s_",true);
 	$query ="";
 	if(empty($cid))
 	{
 		$cid = "c_".md5(uniqid(rand()));//uniqid("s_",true);
 		$query = "INSERT INTO `#@__column` (cid,cname,ctype,parentid,templateid,sid,sortno,display,disabled,updatetime,updateby,tag) Values('$cid','$cname','$ctype','$pid','$tid','$sid','999','0','0','$ntime','$adminid','')";
 	}
 	else 
 	{
 		$query = "UPDATE `#@__column` set
 		cname='$cname',
 		parentid='$pid',
 		templateid='$tid',
 		sid='$sid',
 		ctype='$ctype',
 		display='$display',
 		updatetime='$ntime',
 		updateby='$adminid' where cid='$cid'";
 	}	

	if(!$dsql->ExecNoneQuery($query))
    {
        $gerr = $dsql->GetError();
        ShowMsg("����ʧ��:".str_replace('"','',$gerr),"-1");
        exit();
    }
    else {
    	redirect("columns.php?sid=".$sid."&pid=".$pid);
        exit();
    }	   
	
}